﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using AdoNet = System.Data;
using System.Runtime.CompilerServices;

namespace DataSet4Com
{
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.AutoDispatch)]
    [ComDefaultInterface(typeof(IDataRowList))]
    [Guid("E263071E-FEFD-475C-B6F5-4C87135A2153")]
    public class DataRowList : IDataRowList
    {
        private List<DataRow> _list;

        public DataRowList() : this(null) { }

        public DataRowList(DataRow[] array)
        {
            _list = new List<DataRow>();

            if (array != null)
                _list.AddRange(array);
        }

        [ComVisible(false)]
        public List<DataRow> InternalList
        {
            get { return _list; }
        }

        [DispId(-4)]
        public IEnumerator GetEnumerator()
        {
            return _list.GetEnumerator();
        }

        [DispId(0)]
        [IndexerName("_Default")]
        public DataRow this[int index]
        {
            get
            {
                return _list[index];
            }
        }

        public void Add(DataRow row)
        {
            _list.Add(row);
        }

        public void Clear()
        {
            _list.Clear();
        }

        public bool Contains(DataRow row)
        {
            return _list.Contains(row);
        }

        public int IndexOf(DataRow row)
        {
            return _list.IndexOf(row);
        }

        public void Remove(DataRow row)
        {
            _list.Remove(row);
        }

        public void RemoveAt(int index)
        {
            _list.RemoveAt(index);
        }

        public int Count
        {
            get { return _list.Count; }
        }
    }

    [ComVisible(true)]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    [Guid("692FCF4B-11DA-47DE-A52D-37EAA9A89DD4")]
    public interface IDataRowList
    {
        [DispId(-4)]
        IEnumerator GetEnumerator();

        [DispId(0)]
        [IndexerName("_Default")]
        DataRow this[int index]
        {
            get;
        }

        void Add(DataRow row);

        void Clear();

        bool Contains(DataRow row);

        int IndexOf(DataRow row);

        void Remove(DataRow row);

        void RemoveAt(int index);

        int Count
        {
            get;
        }
    }
}
